package com.ohuang.jiaxiaotong.Banner;

import android.os.Build;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

import com.youth.banner.adapter.BannerAdapter;
import com.youth.banner.util.BannerUtils;

import java.util.List;
import com.ohuang.jiaxiaotong.R;
/**
 * 自定义布局，网络图片
 */
public class ImageNetAdapter extends BannerAdapter<CourseBean,ImageHolder> {

    public ImageNetAdapter(List<CourseBean> mDatas) {
        super(mDatas);
    }

    @Override
    public ImageHolder onCreateHolder(ViewGroup parent, int viewType) {
        ImageView imageView = (ImageView) BannerUtils.getView(parent, R.layout.banner_image);
        //通过裁剪实现圆角
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            BannerUtils.setBannerRound(imageView,20);
        }

        return new ImageHolder(imageView);
    }

    @Override
    public void onBindView(final ImageHolder holder, final CourseBean data, final int position, int size) {
        //通过图片加载器实现圆角，你也可以自己使用圆角的imageview，实现圆角的方法很多，自己尝试哈
        Glide.with(holder.itemView)
                .load(data.imageUrl)
//                .apply(RequestOptions.bitmapTransform(new RoundedCorners(30)))
                .into(holder.imageView);
        holder.imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                imgOnClickListener.imgClick(holder,  data,position);
            }
        });
    }
private ImgOnClickListener imgOnClickListener;

    public void setImgOnClickListener(ImageNetAdapter.ImgOnClickListener imgOnClickListener){
        this.imgOnClickListener=imgOnClickListener;
    }

    public  interface ImgOnClickListener{
        void imgClick(ImageHolder ImageHolder,CourseBean data,int position);
}
}
